 
package com.xbongbong.paas.domain.entity;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.paas.toolbox.wrap.QueryIgnore;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Objects;

/**
* @author autoGen
* @time 2018-08-13 10:41:00
*/
@Setter
@Getter
@ToString
public class PaasFormDataEntity extends Entity {

	private static final long serialVersionUID = 2224400376903616121L;

	//========== properties ==========


	/**
	* 主键
	*/
	private Long id;
	/**
	 * 对应 es 中的 _id
	 * 格式为 corpid_id
	 */
	private String esId;
	/**
	 * 主键 对应 PaasFormDataEntity 的 id
	 * @see com.xbongbong.paas.domain.entity.PaasFormDataEntity
	 */
	private Long dataId;
	/**
	* 公司id
	*/
	private String corpid;
	/**
	* 应用id
	*/
	private Long appId;

	/**
	 * 菜单id
	 */
	private Long menuId;
	/**
	* 表单id
	*/
	private Long formId;

	/**
	* 编号
	*/
	private String serialNo;
	/**
	* 拥有者id
	*/
	private String ownerId;
	/**
	* 部门id
	*/
	private Long departmentId;
	/**
	* 流程状态枚举值
	*/
	private Integer flowStatus;
	/**
	* 表单数据存储json，mysql 5.7 开始支持该格式，并支持检索
	*/
	private JSONObject data;
	/**
	* 创建者id
	*/
	private String creatorId;
	/**
	* 创建时间时间戳
	*/
	private Long addTime;
	/**
	* 更新时间时间戳
	*/
	private Long updateTime;
	/**
	* 删除标记
	*/
	private Integer del;
	/**
	 * 连接字段，命名不符合java规范
	 */
	private String  my_join_field;
	/**
	 * 子表单数据
	 */
	@Getter(onMethod_ = {@QueryIgnore})
	private JSONObject subFormData;
	/**
	 * 孤独子表单数据
	 */
	@Getter(onMethod_ = {@QueryIgnore})
	private JSONObject singleSubFormData;

	/**
	 * 对资金模块来说，该字段的意义为：生成规则，默认值为1;1:手动创建应收 2:按开票产生应收 3:按出库产生应收  @see com.xbongbong.pro.enums.fund.enums.ModelTypeEnum
	 * 如果其他模块也扩展这类系统字段，则代表各自模块的意义，注意写清注释
	 */
	private Long sysLong10;
	/**
	 * 对客户模块来说，该字段的意义为：合同最近签订时间  @see com.xbongbong.saas.enums.base.ManagementBaseEnum
	 * 如果其他模块也扩展这类系统字段，则代表各自模块的意义，注意写清注释
	 */
	private Long sysDate1;
	/**
	 * 对客户模块来说，该字段的意义为：机会的最近创建时间  @see com.xbongbong.saas.enums.base.ManagementBaseEnum
	 * 如果其他模块也扩展这类系统字段，则代表各自模块的意义，注意写清注释
	 */
	private Long sysDate2;

	/**
	 * 回款单那边需要用到
	 */
	@Getter(onMethod_ = {@QueryIgnore})
	private String uuid;

	public PaasFormDataEntity(){
		// serialNo = "";
		del = 0;
	}

	public Long getDataId(){
		if (Objects.isNull(this.dataId)){
			dataId = this.getId();
		}
		return this.dataId;
	}

	public Long getSysDate1(){
		if (Objects.nonNull(data) && Objects.nonNull(data.get(CustomerManagementEnum.CONTRACT_SIGN_DATE.getAttr()))){
			Long contractSignTime = data.getLong(CustomerManagementEnum.CONTRACT_SIGN_DATE.getAttr());
			sysDate1 = contractSignTime;
		}
		return this.sysDate1;
	}


	public Long getSysDate2(){
		if (Objects.nonNull(data) && Objects.nonNull(data.get(CustomerManagementEnum.OPPORTUNITY_ADD_DATE.getAttr()))){
			Long opportunityAddDate = data.getLong(CustomerManagementEnum.OPPORTUNITY_ADD_DATE.getAttr());
			sysDate2 = opportunityAddDate;
		}
		return this.sysDate2;
	}

	public PaasFormDataEntity(Long id, String corpid, Long appId, Long menuId, Long formId, String serialNo, String ownerId, Long departmentId, Integer flowStatus, JSONObject data, String creatorId, Long addTime, Long updateTime, Integer del) {
		this.id = id;
		this.dataId = id;
		this.corpid = corpid;
		this.appId = appId;
		this.menuId = menuId;
		this.formId = formId;
		this.serialNo = serialNo;
		this.ownerId = ownerId;
		this.departmentId = departmentId;
		this.flowStatus = flowStatus;
		this.data = data;
		this.creatorId = creatorId;
		this.addTime = addTime;
		this.updateTime = updateTime;
		this.del = del;
	}
}

